package 完全背包问题;

//import java.util.Scanner;
//
//public class Main {
//    static int N = 1010;
//    static int[][] f = new int[N][N];
//    static int[] v = new int[N];
//    static int[] w = new int[N];
//
//    public static void main(String[] args) {
//        Scanner in = new Scanner(System.in);
//        int n = in.nextInt();
//        int m = in.nextInt();
//        for (int i = 1; i <= n; i++) {
//            v[i] = in.nextInt();
//            w[i] = in.nextInt();
//        }
//        for (int i = 1; i <= n; i++) {
//            for (int j = 1; j <= m; j++) {
//                f[i][j] = f[i - 1][j];
//                if (j >= v[i]) {
//                    f[i][j] = Math.max(f[i][j], f[i][j - v[i]] + w[i]);
//                }
//            }
//        }
//        System.out.println(f[n][m]);
//    }
//}


import java.util.Scanner;

public class Main {
    static int N = 1010;
    static int[] f = new int[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        for (int i = 1; i <= n; i++) {
            int v = in.nextInt();
            int w = in.nextInt();
            for (int j = v; j <= m; j++) {
                f[j] = Math.max(f[j], f[j - v] + w);
            }
        }
        System.out.println(f[m]);
    }
}